#ifndef __PID_H  
#define __PID_H

#include "stm32f407xx.h"

/**
 * @brief 存放PID参数
 * 
 * @param kp kp
 * @param kd kd
 * @param ki ki
 */
typedef struct pid_param
{
  float kp;
  float ki;
  float kd;
  int16_t limit;
  int16_t target;
  int16_t error;
  int16_t measure;
  int16_t error_sum;
  int16_t last_error;

  int32_t p;
  int32_t i;
  int32_t d;
  
  int32_t out;
} pid_param;


// 声明PID控制函数
void PID_control(pid_param *pid_param,int16_t measure,int16_t target);
void PID_angle_control(pid_param *pid_param,int16_t measure,int16_t target);

typedef struct
{
  float kp;
  float ki;
  float kd;

  float i_max;
  float out_max;
  
  float ref; //�趨
  float fdb; //����
  float err[2];

  float p_out;
  float i_out;
  float d_out;
  float output;
}PID_struct_t;

void PID_init(PID_struct_t *PID,float kp,float ki,float kd,float i_max,float out_max);
float PID_Calc_Angle(PID_struct_t *PID, float ref, float fdb);//PID���㺯����Ŀ�꣬ʵ��)
float PID_Calc_Speed(PID_struct_t *PID, float ref, float fdb);//PID���㺯����Ŀ�꣬ʵ�ʣ�
float PID_Calc_Ink(PID_struct_t *PID, float ref, float fdb);//PID���㺯����Ŀ�꣬ʵ�ʣ�
//float PID_Calc_Follow(PID_struct_t *PID, float ref, float fdb);//PID���㺯����Ŀ�꣬ʵ�ʣ�
int Limit_Min_Max(int value,int min,int max);

#endif /* __PID_H */